echo off
set PrjPath=C:\SuperX6\SuperX.IoT
set publishPath=c:\IoT\IoT3.0
set srcPath=c:\IoT
set cmdDir=c:\IoT\bash
echo  %1
cd %publishPath%
md %1
cd %publishPath%\%1
md IoT
cd IoT
md Log
set verPath=%publishPath%\%1\IoT
set verInternal=%publishPath%\%1\IoT
echo Vesion:%1 > \lib\Release.cfg

::复制整个目录到发版文件夹那
xcopy /S /Y /I %PrjPath%\App\IoTServiceCore6\bin\Release\publish %verPath%
cd %srcPath%\Config
::复制配置文件
xcopy %srcPath%\Config %verPath%\lib
::复制库文件
xcopy /S /Y %srcPath%\Lib %verPath%\lib

copy %PrjPath%\SuperX.NLog\Sentinel\Bin\Release %verPath%\Log

::复制Obfuscar代码混淆的
xcopy /S /Y /I %PrjPath%\App\IoTServiceCore6\bin\Release\net6.0\Obfuscar %verPath%\lib
::复制Lib里的内容
xcopy /S /Y /I %publishPath%\Lib %verPath%\lib

::复制netcore驱动
set driverPath=C:\IoT\Driver\latest\netcore
xcopy /S /Y /I %driverPath% %verPath%\lib\Drivers

cd %verPath%\Drivers
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Common.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Common.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Monitoring.Contracts.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Monitoring.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.SIPLACEPro.LineControl.Contracts.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.SIPLACEPro.LineControl.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.WS.Common.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.WS.Eventing.Contracts.dll .

xcopy /S /Y /I %srcPath%\Web %verPath%\lib\Web
copy %srcPath%\ConfigCore %verPath%\lib
xcopy /S /Y /I %srcPath%\Project %verPath%\lib\Project

::
::内部使用未加密版
cd %publishPath%\%1
md IoTInternal
cd IoTInternal
set verInternal=%publishPath%\%1\IoTInternal
md Log
md Drivers
md Lib
md Services
md Web
md zh-Hans
md Project
copy %PrjPath%\App\IoTServiceCore6\bin\Release\IoTServiceNet45.exe .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\IoTServiceNet45.exe.config .
copy %PrjPath%\App\Listener\ListenerService\bin\Release\ListenerService.exe .
copy %PrjPath%\App\Listener\ListenerService\bin\Release\ListenerService.exe.config .
copy %PrjPath%\App\IoTServiceWinService\bin\Release\IoTServiceWinService.exe .
copy %PrjPath%\App\IoTServiceWinService\bin\Release\IoTServiceWinService.exe.config .
xcopy /S /Y %PrjPath%\App\IoTServiceCore6\bin\Release\Script Script\

xcopy /S /Y /I %PrjPath%\App\IoTServiceCore6\bin\Release\publish %verInternal%

copy %srcPath%\Config .

set release=%PrjPath%\App\IoTServiceCore6\bin\Release
cd C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\Extensions\PreEmptiveSolutions\DotfuscatorCE
::代码编译混淆
copy %release%\SuperX.ORM.dll %verInternal%\Lib
copy %release%\SuperX.Common.dll %verInternal%\Lib
copy %release%\SuperX.CoreService.dll %verInternal%\Lib
copy %release%\SuperX.Database.dll %verInternal%\Lib
copy %release%\SuperX.DataService.dll %verInternal%\Lib
copy %release%\SuperX.Helper.dll %verInternal%\Lib
copy %release%\SuperX.ProjectManager.dll %verInternal%\Lib
copy %release%\SuperX.ModelBase.dll %verInternal%\Lib
copy %release%\SuperX.ListenerService.dll %verInternal%\Lib
copy %release%\RabbitMQDotNetClient.dll %verInternal%\Lib
copy %PrjPath%\Database\InfluxDB.Client.Net\bin\Release\net45\InfluxDB.Client.Net.dll %verInternal%\Lib
copy %release%\SuperX.SqlSugar.dll %verInternal%\Lib

cd %verInternal%\Lib
copy %PrjPath%\SuperX.TimeManagerService\bin\Release\net45\SuperX.TimeManagerService.dll .
copy %PrjPath%\SuperX.WebSocketService\bin\Release\net45\SuperSocket.WebSocket.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\CommonServiceLocator.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\M2Mqtt.Net.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\NPOI.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\NPOI.OOXML.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\NPOI.OpenXml4Net.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\NPOI.OpenXmlFormats.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\ICSharpCode.SharpZipLib.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\Fleck.dll .
copy %PrjPath%\App\IoTServiceCore6\bin\Release\MySql.Data.dll .

copy %PrjPath%\SuperX.NLog\Sentinel\Bin\Release %verInternal%\Log

::复制net驱动
set driverPath=C:\IoT\Driver\latest\net
xcopy /S /Y %driverPath% %verInternal%\Drivers

cd %verInternal%\Drivers
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Common.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Common.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Monitoring.Contracts.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.Monitoring.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.SIPLACEPro.LineControl.Contracts.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.SIPLACEPro.LineControl.Proxy.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.WS.Common.dll .
copy %PrjPath%\Drivers\SuperX.ASM.OIB\bin\Release\net45\Asm.As.Oib.WS.Eventing.Contracts.dll .

cd %verInternal%

xcopy 

xcopy /S /Y %srcPath%\Web %verInternal%\Web
xcopy /S /Y %srcPath%\Project %verInternal%\Project

::压缩
"C:\Program Files\WinRAR\Rar.exe" a -ep1 %verPath% %publishPath%\%1\IoT

"C:\Program Files\7-Zip\7z.exe" a -tzip %verPath% %publishPath%\%1\IoT\*

::删除latest文件夹
xcopy /S /Y /I %verPath% %publishPath%\latest

::打包
::版本
::设置AdvancedInstaller.com的绝对路径变量
set advinst="C:\Soft\AdvancedInstaller 20.2 cn\AdvancedInstaller 20.2 cn\App\bin\x86\AdvancedInstaller.com"

::设置需要打包项目的工程文件的绝对路径
set aip="C:\IoT\AdvanceProj\IoTSetup.aip"
::设置版本

::修改langid为2052、随机生成guid
%advinst% /edit %aip% /SetProductCode -langid 2052
%advinst% /edit %aip% /SetVersion %1
::重新打包 
%advinst% /rebuild %aip%

set package=C:\IoT\package
::复制安装包
xcopy /S /Y %package%\IoTSetup.exe %publishPath%\%1

::2.0相关操作↓
echo IoTCore开始打包...
cd %publishPath%
md %1
cd %publishPath%\%1
md IoTCore
cd IoTCore
set IoTCoreDir=%cd%

copy %release%\Asm.As.Oib.WS.Eventing.Contracts.dll .

::更新包
"C:\Program Files\7-Zip\7z.exe" a -tzip %IoTCoreDir% %IoTCoreDir%\*
::2.0相关操作↑

exit 0